<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<meta name="description" content="">
		<meta name="author" content="">

		<title>Dashboard Template for Bootstrap</title>
		<!-- Bootstrap core CSS -->
		<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
		<!-- Custom styles for this template -->
		<link th:href="@{/css/dashboard.css}" rel="stylesheet">
		<style type="text/css">
			/* Chart.js */
			@-webkit-keyframes chartjs-render-animation {
				from {
					opacity: 0.99
				}
				to {
					opacity: 1
				}
			}
			@keyframes chartjs-render-animation {
				from {
					opacity: 0.99
				}
				to {
					opacity: 1
				}
			}
		</style>
	</head>

	<body>
	<div th:replace="~{commons/commons::topbar}"></div>
		<div class="container-fluid">
			<div class="row">
				<div th:replace="~{commons/commons::sidebar(active='listStudent.html')}"></div>
				<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
					<div class="table-responsive">
						<table class="table table-striped table-sm">
							<thead>
							<tr>
								<td>
									<a th:class="${active == '/addStudent.html'?'nav-link active':'nav-link'}" th:href="@{/admin/toAddStudent}">
										<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"></path>
										<polyline points="13 2 13 9 20 9"></polyline>
										新增学生 <span class="sr-only"></span>
									</a>
								</td>
								<td>
									<a th:class="${active == '/getStudent.html'?'nav-link active':'nav-link'}" th:href="@{/admin/toGetStudent}">
										<circle cx="9" cy="21" r="1"></circle>
										<circle cx="20" cy="21" r="1"></circle>
										<path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path>
										搜索学生 <span class="sr-only"></span>
									</a>
								</td>
								<td>
									<a th:class="${active == '/uploadExcel.html'?'nav-link active':'nav-link'}" th:href="@{/admin/toUploadExcel}">
										<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path>
										<circle cx="9" cy="7" r="4"></circle>
										<path d="M23 21v-2a4 4 0 0 0-3-3.87"></path>
										<path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
										批量导入学生信息 <span class="sr-only"></span>
									</a>
								</td>
								<td>
									<a th:class="${active == '/uploadExcel.html'?'nav-link active':'nav-link'}" th:href="@{/admin/exportData}">
										<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path>
										<circle cx="9" cy="7" r="4"></circle>
										<path d="M23 21v-2a4 4 0 0 0-3-3.87"></path>
										<path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
										导出学生信息 <span class="sr-only"></span>
									</a>
								</td>
							</tr>
							<tr>
								<th>姓名</th>
								<th>身份证号码</th>
								<th>年龄</th>
								<th>地址</th>
								<th>操作</th>
							</tr>
							</thead>
							<tbody>
							<tr th:each="student : ${students}">
								<td th:text="${student.getName()}"></td>
								<td th:text="${student.getIdCard()}"></td>
								<td th:text="${student.getAge()}"></td>
								<td th:text="${student.getAddress()}"></td>
								<td>
									<a th:href="@{/admin/toUpdateStudent/}+${student.getId()}">修改</a>
									<input type="button" th:id="${student.getId()}" onclick="javascript:
									var num = event.target.id;
									var num1 = document.getElementById(num);
									var stuId = num1.getAttribute('id');
									var msg = '您真的确定要删除吗？';
									if (confirm(msg)==true){
										$.ajax({
											url:'http://localhost:8080/admin/deleteStudent',
											type: 'GET',
											data:{'studentId':stuId},
											datatype: 'json',
											success: function (data) {
												if(data.code == '0'){
													window.location.href = 'http://localhost:8080/admin/listStudent';
												}else if (data.code == '1'){
													alert('年龄或身份证数据格式有误');
												}else if (data.code == '4'){
													alert('数据正处于修改状态，不能删除！');
												}else {
													alert('异常');
												}
											}
										});
									}" value="删除"/>
								</td>
							</tr>
							<tr>
								<td colspan="8">
									<div class="pagelist">
										<p>当前<span th:text="${students.getNumber()} + 1"></span>页,总<span th:text="${students.totalPages}"></span>页
											　　　　　　　　　　　　　　　　　共<span th:text="${students.totalElements}"></span>条记录
											<a th:href="@{/admin/listStudent}">首页</a>
											<a th:href="@{/admin/listStudent(pageNum = ${students.hasPrevious()} ? ${students.getNumber() } : 1)}">上一页</a>
											<a th:href="@{/admin/listStudent(pageNum = ${students.hasNext()} ? ${students.getNumber()} + 2 : ${students.totalPages})}">下一页</a>
											<a th:href="@{/admin/listStudent(pageNum = ${students.totalPages})}">尾页</a></p>
									</div>
								</td>
							</tr>
							</tbody>
						</table>
					</div>
				</main>
			</div>
		</div>
		<!-- Bootstrap core JavaScript
    ================================================== -->
		<!-- Placed at the end of the document so the pages load faster -->
		<script type="text/javascript" th:src="@{/js/jquery-3.4.1.min.js}"/>
		<script type="text/javascript" th:src="@{/js/jquery-3.2.1.slim.min.js}"></script>
		<script type="text/javascript" th:src="@{/js/popper.min.js}"></script>
		<script type="text/javascript" th:src="@{/js/bootstrap.min.js}"></script>

		<!-- Icons -->
		<script type="text/javascript" th:src="@{/js/feather.min.js}"></script>
		<script>
			feather.replace()
		</script>
	</body>
</html>